#include <iostream>
#include <cstring>
using namespace std;
// #define ONLINE_GUDGE

const int N = 2e5+10;

int n, k; // n -> k
int q[N];
int dist[N]; // 判重 state


void bfs()
{
    int hh = 0, tt = 0; // 数组模拟队列
    q[0] = n;
    dist[n] = 0;
    
    while(hh <= tt)
    {
        int t = q[hh++];
        if(t == k) break;
        if(t + 1 < N && dist[t+1] > dist[t] + 1) // case1 向前走一步
            dist[t+1] = dist[t] + 1, q[++tt] = t+1;

        if(t - 1 < N && dist[t-1] > dist[t] + 1) // case2 向后走一步
            dist[t-1] = dist[t] + 1, q[++tt] = t-1;

        if(t * 2 < N && dist[t*2] > dist[t] + 1) // case1 向后走一步
            dist[t*2] = dist[t] + 1, q[++tt] = t*2;
        
    }
}

int main()
{

    #ifdef ONLINE_JUDGE

    #else
    freopen("./in.txt","r",stdin);
    #endif
    ios::sync_with_stdio(false);   
	cin.tie(0);
    int t = 1; // cin >> t;  
    
    while(t--)
    {
        cin >> n >> k; 

        memset(dist, 0x3f, sizeof dist);
        bfs();
        cout << dist[k] << endl;
    }
    

    return 0;
}